package com.ljj.controller;


import com.github.pagehelper.PageInfo;
import com.ljj.pojo.College;
import com.ljj.pojo.Student;
import com.ljj.service.CollegeService;
import com.ljj.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LJJ
 * @since 2020-07-11
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @Autowired
    CollegeService collegeService;



//    根据学院id查询学生
    @RequestMapping("/selStuByCid")
    public String queryStudentCid(@RequestParam(required = true, value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = true, value = "pageSize", defaultValue = "5") Integer pageSize,
                                  int cid, Model model) {
        PageInfo<Student> students = studentService.queryStuByCidPage(cid, pageNum, pageSize);
//       可以用多表一起查出来，后期来优化
        List<College> colleges = collegeService.QueryCollege();
        model.addAttribute("colleges", colleges);
        model.addAttribute("pageInfoL",students);
        model.addAttribute("type", "cid");
        model.addAttribute("cid", cid);
        return "student/student";
    }


    //查询所有学生
    @RequestMapping("/allStu")
    public String selectStu(@RequestParam(required = true, value = "pageNum", defaultValue = "1") Integer pageNum,
                            @RequestParam(required = true, value = "pageSize", defaultValue = "5") Integer pageSize,
                             Model model) {

        PageInfo<Student> students = studentService.queryStudentsPage(pageNum, pageSize);
        List<College> colleges = collegeService.QueryCollege();
        model.addAttribute("colleges", colleges);
        model.addAttribute("pageInfoL", students);
        model.addAttribute("type", "all");
        return "student/student";
    }

}

